/**
 * MainPageTask.java $version 1.0 Jul 3, 2012
 *
 * Copyright 2011 Pravin Kumar Corp. All rights Reserved.
 * Pravin Kumar PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package com.app.tablet.data.tasks;

import java.sql.SQLException;

import android.database.Cursor;
import android.util.Log;

import com.app.tablet.data.dao.TabletDao;
import com.app.tablet.data.db.TabletDB;
import com.app.tablet.notify.Notifier;

/**
 * Provide a brief description of MainPageTask.
 * Specify the following items:
 * - What does it do.
 * - Its dependencies.
 * - What section / item in the class document does it correspond to.
 * 
 * @author
 */
public class MainPageTask extends AbstractTask <Object, Void, Cursor>{

	private String Tag = "MainPageTask";

	/**
	 * Provide a brief description of MainPageTask constructor.
	 * Specify the purpose of this constructor.
	 * 
	 * @param notifier
	 */
	public MainPageTask(Notifier notifier) {

		super(notifier);
		// TODO Auto-generated constructor stub
	}

	/**
	 * Why are you overriding this method and what are you achieving here?
	 */
	@Override
	protected Cursor doInBackground(Object... arg0) {
		Cursor mainPageCursor = null;
		try{
			mainPageCursor = TabletDao.getTabletDao().getAllTablets(TabletDB.getInstance());
			
			//TabletDB.getInstance().dumbData();
		} catch(SQLException e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Log.i(Tag, "Main Page Cursor :" + mainPageCursor.getCount());
		return mainPageCursor;

	}

	protected void onProgressUpdate(Integer... progress) {

	}

	protected void onPostExecute(Cursor result) {
		
		if(result != null){
			getNotifier().onSuccess(result);
		} else{
			getNotifier().onError();
		}

	}

}
